package com.fancy.mobileschool.ui.adapt;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fancy.mobileschool.R;
import com.fancy.mobileschool.entity.Course;
import com.fancy.mobileschool.ui.ChatGroupRoomActivity;

import java.util.List;

/**
 * Created by Jackie on 2017/11/4.
 */

public class ChatGroupListAdapt extends RecyclerView.Adapter<ChatGroupListAdapt.Group> {

    private Context context;

    private List<Course> courses;

    public ChatGroupListAdapt(Context context, List<Course> courses) {
        this.context = context;
        this.courses = courses;
    }

    @Override
    public Group onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.chat_group_item, parent, false);
        return new Group(view);
    }

    @Override
    public void onBindViewHolder(Group holder, int position) {
        Course course = courses.get(position);
        holder.courseName.setText(course.name);
        holder.intro.setText("学分： " + course.credict + " 学时: " + course.class_num);
        holder.course_id = course.course_id;
    }

    @Override
    public int getItemCount() {
        return courses.size();
    }



    class Group extends RecyclerView.ViewHolder implements View.OnClickListener{

        private TextView courseName;

        private TextView intro;

        private String course_id;

        public Group(View itemView) {
            super(itemView);
            courseName = (TextView) itemView.findViewById(R.id.chat_group_item_name);
            intro = (TextView) itemView.findViewById(R.id.chat_group_item_intro);
            itemView.setOnClickListener(this);
        }


        @Override
        public void onClick(View view) {
            Intent intent = new Intent(context, ChatGroupRoomActivity.class);
            intent.putExtra("course_id", course_id);
            context.startActivity(intent);
        }
    }
}
